﻿
$.MGJ.LeadCode = [];

(function () {
    var _this = $.MGJ.LeadCode;
    $.extend($.MGJ.LeadCode, { 
        //详细数据
        Dialog_LeadShowDataObj: null,
        Dialog_LeadShowData: function (obj) {
            var id = $(obj).attr("LID");
            this.Dialog_LeadShowDataObj = $.L.dialog({
                url: ACTION_URL("LeadShowData", "CodeManage") + "?id=" + id,
                title: "详细数据",
                width: 1100,
                height: "auto",
                buttons: {
                   
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });


        },




        //导码
        Dialog_LeadOutObj: null,
        Dialog_LeadOut: function (obj) {
            var Batch = $(obj).attr("Batch");
            var ID = $(obj).attr("ID");
            var Code = $(obj).attr("Code");
            var EnterpriseName = $(obj).attr("EnterpriseName");
            this.Dialog_LeadOutObj = $.L.dialog({
                url: ACTION_URL("LeadOut", "CodeManage") + "?patch=" + Batch + "&enterId=" + Code + "&batchId=" + ID + "&eName=" + EnterpriseName,
                title: "导码",
                width: 600,
                height: "auto",
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            //_this.Ajax_leadCodeSave();
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
           

        }

    });
})(jQuery);
(function () {
    var _this = $.MGJ.LeadCode;
    $.extend($.MGJ.LeadCode, {


    });
})(jQuery);

(function () {
    var _index = 1;
    var _this = $.MGJ.LeadCode;
    $.extend($.MGJ.LeadCode, {
        //分页   
        Ajax_LeadCodePageList: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#Lsearch").val());
            $.L.ajaxHandle({
                url: ACTION_URL("LeadCodePageList", "CodeManage"),
                data: {
                    Lsearch: window.SearchKey,
                    pageIndex: pageIndex,
                    pageSize: 10
                },
                success: function (response) {
                    $("#LeadTable").L_bindingDataList(response);
                    $("#LeadTable_left").L_bindingDataList(response);
                    $("#LeadTable_right").L_bindingDataList(response);
                }
            });
        },
        Ajax_handes: function (obj) {
            var temp = obj.split(",");
            var result = "";
            for (i = 0; i < temp.length ; i++) {
                if (temp[i] == 1) {
                    result += " 防伪码 ";
                } else if (temp[i] == 2) {
                    result += " 管理码 ";
                } else if (temp[i] == 3) {
                    result += " 积分码 ";
                }
            }
            return result;
        },
        Ajax_IntStatus: function (obj) {
            return obj == 0 ? "待生码" : "已成功";
        },
        Ajax_ViewFlag: function (obj) {
            return obj == 0 ? "禁用" : "启用";
        },
        Ajax_DelLeadCode: function (obj) {
            $.L.msgConfirm("确认删除该记录?", function () {
                var id = $(obj).attr("LID");
                $.L.ajaxHandle({
                    url: ACTION_URL("DelLeadCode", "CodeManage") + "?id=" + id,
                    data: { id: id },
                    success: function (response) {
                        if (response > 0) {
                            _this.Ajax_LeadCodePageList(_index);
                            $.L.msgSuccess("操作成功！");
                        }
                    }
                });
            })
        },
        //启动禁止
        Ajax_GetViewFlags: function (flge) {
            var CheckValue = "";
            var CheckFlag = "";
            $('input[name="AllClickChild"]:checked').each(function () {
                CheckValue += "," + $(this).val();
                CheckFlag += "," + $(this).attr("flag");
            });
            checkValue_ = CheckValue.substring(1);
            CheckValueArr = CheckValue.substring(1).split(",");
            CheckFlagArr = CheckFlag.substring(1).split(",");
            if (CheckValue == "") {
                $.L.msgError("请先选中一项！");
            } else {
                var CheckFlagArrAdd = 0;
                for (var i = 0; i < CheckFlagArr.length; i++) {
                    CheckFlagArrAdd += parseInt(CheckFlagArr[i]);
                }
                var str = "";
                if (flge == 0) {
                    if (CheckFlagArrAdd != 0) {
                        str = "禁用";
                        $.L.msgConfirm("确定" + str + "吗？", function () {
                            $.L.ajaxHandle({
                                url: ACTION_URL("GetViewFlag", "CodeManage"),
                                data: { flge: flge, CheckValue: checkValue_ },
                                success: function (response) {
                                    if (response > 0) {
                                        _this.Ajax_LeadCodePageList(1)
                                        //$('input[name="AllClickChild"]:checked').each(function () {
                                        //    $(this).attr("flag", "0")
                                        //});
                                        $.L.msgSuccess("操作成功");
                                    }
                                }
                            });
                        })
                    } else {
                        $.L.msgError('已禁用！');
                    }
                } else {
                    str = "启用";
                    if (CheckFlagArrAdd != CheckFlagArr.length) {
                        $.L.msgConfirm("确定" + str + "吗？", function () {
                            $.L.ajaxHandle({
                                url: ACTION_URL("GetViewFlag", "CodeManage"),
                                data: { flge: flge, CheckValue: checkValue_ },
                                success: function (response) {
                                    
                                   
                                    if (response > 0) {
                                        _this.Ajax_LeadCodePageList(1)
                                        //$('input[name="AllClickChild"]:checked').each(function () {
                                        //    $(this).attr("flag", "1")
                                        //});
                                        $.L.msgSuccess("操作成功");
                                    }
                                }
                            });
                        })
                    }
                    else {
                        $.L.msgError('已启用！');
                    }
                }
            }
        }

        
});

})(jQuery);
